home *** CD-ROM | disk | FTP | other *** search
/ Utilities Professional 1-1500 / Utilities Professional 1-1500 (1994)(WPD)[!].iso / 12511500 / var1459.dms / var1459.adf / Fonts / Example2.c < prev    next >
C/C++ Source or Header  |  1992-04-28  |  7KB  |  209 lines

  1. /***********************************************************/
  2. /*                                                         */
  3. /* Amiga C Encyclopedia (ACE) V3.0      Amiga C Club (ACC) */
  4. /* -------------------------------      ------------------ */
  5. /*                                                         */
  6. /* Book:    ACM Graphics                Amiga C Club       */
  7. /* Chapter: Fonts                       Tulevagen 22       */
  8. /* File:    Example2.c                  181 41  LIDINGO    */
  9. /* Author:  Anders Bjerin               SWEDEN             */
  10. /* Date:    92-04-28                                       */
  11. /* Version: 1.00                                           */
  12. /*                                                         */
  13. /*   Copyright 1992, Anders Bjerin - Amiga C Club (ACC)    */
  14. /*                                                         */
  15. /* Registered members may use this program freely in their */
  16. /*     own commercial/noncommercial programs/articles.     */
  17. /*                                                         */
  18. /***********************************************************/
  19.  
  20. /* This example demonstrates how to change the style of */
  21. /* a font. We will open the ROM font "Topaz" and change */
  22. /* the style to underlined, bold and italic. Well, we   */
  23. /* try to use all mentioned styles, but it may happen   */
  24. /* that we are not allowed to use some styles.          */
  25.  
  26.  
  27.  
  28. #include <intuition/intuitionbase.h>
  29.  
  30.  
  31. struct Intuition *IntuitionBase; /* Running under Intuition. */
  32. struct GfxBase *GfxBase;         /* Move() and Text().       */
  33.  
  34.  
  35. /* The new font's attributes: */
  36. struct TextAttr my_font_attr=
  37. {
  38.   "topaz.font", /* Name of the font.  */
  39.   8,            /* Height (in pixels) */
  40.   FS_NORMAL,    /* Style              */
  41.   FPF_ROMFONT   /* Exist in ROM.      */
  42. };
  43.  
  44. /* Pointer to our new font: */
  45. struct TextFont *my_font;
  46.  
  47.  
  48.  
  49. /* Declare a pointer to a Window structure: */ 
  50. struct Window *my_window;
  51.  
  52. /* Declare and initialize your NewWindow structure: */
  53. struct NewWindow my_new_window=
  54. {
  55.   0,             /* LeftEdge    x position of the window. */
  56.   12,            /* TopEdge     y positio of the window. */
  57.   640,           /* Width       640 pixels wide. */
  58.   100,           /* Height      100 lines high. */
  59.   0,             /* DetailPen   Text should be drawn with colour reg. 0 */
  60.   1,             /* BlockPen    Blocks should be drawn with colour reg. 1 */
  61.   CLOSEWINDOW,   /* IDCMPFlags  The window will give us a message if the */
  62.                  /*             user has selected the Close window gad. */
  63.   SMART_REFRESH| /* Flags       Intuition should refresh the window. */
  64.   WINDOWCLOSE|   /*             Close Gadget. */
  65.   WINDOWDRAG|    /*             Drag gadget. */
  66.   WINDOWDEPTH|   /*             Depth arrange Gadgets. */
  67.   ACTIVATE,      /*             The window should be Active when opened. */
  68.   NULL,          /* FirstGadget No Custom gadgets. */
  69.   NULL,          /* CheckMark   Use Intuition's default CheckMark. */
  70.   "Nice Style!", /* Title       Title of the window. */
  71.   NULL,          /* Screen      Connected to the Workbench Screen. */
  72.   NULL,          /* BitMap      No Custom BitMap. */
  73.   0,             /* MinWidth    No sizing gadget. */
  74.   0,             /* MinHeight          -"-        */
  75.   0,             /* MaxWidth           -"-        */
  76.   0,             /* MaxHeight          -"-        */
  77.   WBENCHSCREEN   /* Type        Connected to the Workbench Screen. */
  78. };
  79.  
  80.  
  81.  
  82. void main();
  83. void clean_up();
  84.  
  85. void main()
  86. {
  87.   BOOL close_me;                   /* Used in the loop.       */
  88.   ULONG class;                     /* IDCMP flag.             */
  89.   struct IntuiMessage *my_message; /* IntuiMessage structure. */
  90.  
  91.  
  92.   UWORD style;     /* Desired style.  */
  93.   UWORD a_style;   /* Styles allowed. */
  94.   UWORD new_style; /* Style we got.   */
  95.  
  96.  
  97.   /* Open the necessary libraries: */
  98.   IntuitionBase = (struct IntuitionBase *)
  99.     OpenLibrary( "intuition.library", 0 );
  100.   if( !IntuitionBase )
  101.     clean_up( "Could not open Intuition library!" );
  102.  
  103.   GfxBase = (struct GfxBase *)
  104.     OpenLibrary( "graphics.library", 0 );
  105.   if( !GfxBase )
  106.     clean_up( "Could not open Graphics library!" );
  107.  
  108.  
  109.   /* Open a window in which we will display the new font: */
  110.   my_window = (struct Window *) OpenWindow( &my_new_window );
  111.   
  112.   /* Have we opened the window succesfully? */
  113.   if(my_window == NULL)
  114.     clean_up( "Could not open the window!" );
  115.  
  116.  
  117.  
  118.   /* Set colour and draw mode: */
  119.   SetAPen( my_window->RPort, 1 );
  120.   SetDrMd( my_window->RPort, JAM1 );
  121.  
  122.   /* Try to open a ROM font: */
  123.   my_font = (struct TextFont *)
  124.     OpenFont( &my_font_attr );
  125.  
  126.   /* Have we opened the font successfully? */
  127.   if( !my_font )
  128.     clean_up( "Could not open the font \"Topaz 9\"!" );
  129.  
  130.   /* Change the window's default font: */
  131.   SetFont( my_window->RPort, my_font );
  132.  
  133.   /* Set the desired style: */
  134.   style = FSF_UNDERLINED | FSF_BOLD | FSF_ITALIC;
  135.  
  136.   /* Check which styles we may use: */
  137.   a_style = AskSoftStyle( my_window->RPort );
  138.   
  139.   /* Change the window's font style: */
  140.   new_style = SetSoftStyle( my_window->RPort, style, a_style );
  141.  
  142.   /* Tell the user what style we will use: */
  143.   printf( "Style:" );
  144.   if( new_style )
  145.     printf( "%s%s%s!\n",
  146.       new_style & FSF_UNDERLINED ? " Underlined" : "",
  147.       new_style & FSF_BOLD ? " Bold" : "",
  148.       new_style & FSF_ITALIC ? " Italic" : "" );
  149.   else
  150.     printf( " normal\n!" );
  151.  
  152.   /* Position the cursor, and print some characters: */
  153.   Move( my_window->RPort, 5, 35 );
  154.   Text( my_window->RPort, "ABCDEFGHIJKLMNOPQRSTUVWXYZ 1234567890", 37 );
  155.   Move( my_window->RPort, 5, 50 );
  156.   Text( my_window->RPort, "abcdefghijklmnopqrstuvwxyz !@#$%^&*()", 37 );
  157.  
  158.  
  159.  
  160.   /* Wait until the user closes the window: */
  161.   close_me = FALSE;
  162.   while( close_me == FALSE )
  163.   {
  164.     /* Wait until we have recieved a message: */
  165.     Wait( 1 << my_window->UserPort->mp_SigBit );
  166.  
  167.     /* Collect the message: */
  168.     while( (my_message = (struct IntuiMessage *) GetMsg( my_window->UserPort )) )
  169.     {
  170.       /* After we have collected the message we can read it, and save any */
  171.       /* important values which we maybe want to check later: */
  172.       class = my_message->Class;
  173.  
  174.       /* After we have read it we reply as fast as possible: */
  175.       /* REMEMBER! Do never try to read a message after you have replied! */
  176.       /* Some other process has maybe changed it. */
  177.       ReplyMsg( my_message );
  178.  
  179.       /* Check which IDCMP flag was sent: */
  180.       if( class == CLOSEWINDOW )
  181.         close_me=TRUE; /* The user selected the Close window gadget! */  
  182.     }
  183.   }
  184.  
  185.  
  186.   clean_up( "The End" );
  187. }
  188.  
  189. void clean_up( message )
  190. STRPTR message;
  191. {
  192.   if( my_window )
  193.     CloseWindow( my_window );
  194.  
  195.   if( my_font )
  196.     CloseFont( my_font );
  197.  
  198.   if( GfxBase )
  199.     CloseLibrary( GfxBase );
  200.  
  201.   if( IntuitionBase )
  202.     CloseLibrary( IntuitionBase );
  203.   
  204.   printf( "%s\n", message );
  205.  
  206.   exit();
  207. }
  208.  
  209.